let project = {}

onload = () => {
  project = $util.getPageParam('countProject')
  console.log(project, 'project')
  console.log($('#respondentName').val(), 'respondentName')
  fetchcountProjectList1()
}

const fetchcountProjectList1 = () => {
  let params = {
    projectId:project.id
  }
  $.ajax({
    url: API_BASE_URL + '/searchAS',
    type: 'POST',
    data: JSON.stringify(params),
    dataType: 'json',
    contentType: 'application/json',
    success(res) {
      $('#table #tbody').html('')
      userList = res.data
      res.data.map((item, index) => {
        var time=new Date(+new Date(new Date(item.time).toJSON())+8*3600*1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
        // var stopTime=new Date(+new Date(new Date(item.stopTime).toJSON())+8*3600*1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
        $('#table #tbody').append(`
          <tr>
            <td>${index + 1}</td>
            <td>${item.questionnaireName}</td>
            <td>${item.respondentName}</td>
            <td>${time}</td>
            <td>
              <button type="button" class="btn btn-link" onclick="viewDetail('${item.id}')">明细</button>
            </td>
          </tr>
        `)
      })
    }
  })
}

const fetchcountProjectList = () => {
  let params = {
    projectId:project.id,
    respondentName: $('#respondentName').val()
  }
  $.ajax({
    url: API_BASE_URL + '/searchASByRespondentName',
    type: 'POST',
    data: JSON.stringify(params),
    dataType: 'json',
    contentType: 'application/json',
    success(res) {
      $('#table #tbody').html('')
      userList = res.data
      res.data.map((item, index) => {
        var time=new Date(+new Date(new Date(item.time).toJSON())+8*3600*1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
        // var stopTime=new Date(+new Date(new Date(item.stopTime).toJSON())+8*3600*1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
        $('#table #tbody').append(`
          <tr>
            <td>${index + 1}</td>
            <td>${item.questionnaireName}</td>
            <td>${item.respondentName}</td>
            <td>${time}</td>
            <td>
              <button type="button" class="btn btn-link" onclick="viewDetail('${item.id}')">明细</button>
            </td>
          </tr>
        `)
      })
    }
  })
}
/*
查看明细
 */
const viewDetail = (id) => {
  location.href = "/pages/answer/index.html"
}
// const deleteUser = (username) => {
//   let params = {
//     username:username
//   }
//   $.ajax({
//     url: API_BASE_URL + '/admin/deleteUserinfo',
//     type: 'POST',
//     data: JSON.stringify(params),
//     //data:params,
//     dataType: 'json',
//     contentType: 'application/json',
//     success(res) {
//       fetchUserList()
//     }
//   })
// }
// const resetpassword = (username) => {
//   let params = {
//     username:username
//   }
//   $.ajax({
//     url: API_BASE_URL + '/admin/resetpassword',
//     type: 'POST',
//     data: JSON.stringify(params),
//     //data:params,
//     dataType: 'json',
//     contentType: 'application/json',
//     success(res) {
//       fetchUserList()
//     }
//   })
// }
// const changestatus = (username) => {
//   let params = {
//     username:username
//   }
//   $.ajax({
//     url: API_BASE_URL + '/admin/changestatus',
//     type: 'POST',
//     data: JSON.stringify(params),
//     //data:params,
//     dataType: 'json',
//     contentType: 'application/json',
//     success(res) {
//       fetchUserList()
//     }
//   })
// }
// const handleTableChange = (page) => {
//   if (page === 1) {
//     if (pageNum === 1) return
//     pageNum--
//   } else if (page === 2) {
//     pageNum++
//   } else if (page === 3) {
//     pageNum = +$('#goNum').val()
//   }
//   $('#currentPage').text(pageNum)
//   fetchUserList()
// }
//
// const handleCreateUser = () => {
//   $util.setPageParam('user', undefined)
//   location.href = '/pages/createUser/index.html'
// }
//
// const handleEdit = (username) => {
//   let user = userList.filter(item => item.username === username)[0]
//   $util.setPageParam('user', user)
//   location.href = '/pages/editUser/index.html'
// }
